package proyecto.gestionarDatosDeCursos;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import proyecto.BusinessLogic.CursoBLRemote;
import util.Common;
  
public class EliminarCursoAction extends Action {

	public ActionForward execute(
			ActionMapping mapping,
			ActionForm form,			
			HttpServletRequest request,
			HttpServletResponse response) {
						
			//CursoDAOLocal cursoDAORemote = null;
			CursoBLRemote cursoBLRemote = null;
			final Context context;
		
			AltaCursoForm cursoForm =
			(AltaCursoForm) form;			
											
			if (isCancelled(request)){				
				return mapping.findForward(Common.SHOWLIST);
			}
			else{			
				try
				{							
					context = new InitialContext();					
					//cursoDAORemote = (CursoDAOLocal) context.lookup("CursoDAO/remote");
					cursoBLRemote = (CursoBLRemote) context.lookup("CursoBL/remote");
				} catch (NamingException e)				{
					e.printStackTrace();
					throw new RuntimeException(e);				
				}
				
				//Remove curso
				//cursoDAORemote.remove(cursoForm.getIdCurso());
				cursoBLRemote.remove(cursoForm.getIdCurso());
								
				return mapping.findForward(Common.SHOWLIST);				
		}
	}
	
}
